<?php

namespace app\api\model;

use think\Model;

class Role extends Model
{


    public function add($data)
    {

        $this->startTrans();
        try {
            $this->allowField(['name','menu_ids','meta_name','status','time','content'])->save($data);
            $this->commit();
            return re_success("添加成功");
            // 提交事务
        } catch (\Exception $e) {
            // 回滚事务
            $this->rollback();
            return re_error($e->getMessage());
        }
    }


    public function edit($data)
    {
        $model = Role::find($data['id']);
        $model->startTrans();
        try {
            $model->allowField(['name','menu_ids','meta_name','status','content'])->save($data);
            $model->commit();
            return re_success("修改成功");
            // 提交事务
        } catch (\Exception $e) {
            // 回滚事务
            $model->rollback();
            return re_error($e->getMessage());
        }
    }

    public function dele($id)
    {

        $model = Role::find($id);
        $model->startTrans();
        try {
            $model->delete();
            $model->commit();
            return re_success();
            // 提交事务
        } catch (\Exception $e) {
            // 回滚事务
            $model->rollback();
            return re_error($e->getMessage());
        }
    }
}